package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminSetmealController")
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetMealController {
    @Autowired
    private SetMealService setMealService;


    /**
     * 新增套餐
     * @param dto
     * @return
     */
    @PostMapping
    @CacheEvict(value = "setmealCache" ,key = "#dto.categoryId")
    public Result addSetMeal(@RequestBody SetmealDTO dto){
        return setMealService.addSetMeal(dto);
    }

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public Result pageQuery(SetmealPageQueryDTO dto){
        log.info("开始分页查询");
        return setMealService.pageQuery(dto);
    }

    /**
     * 根据id删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    @CacheEvict(value = "setmealCache" ,allEntries = true)
    public Result deleteSetMeal(@RequestParam List<Long> ids){
        return setMealService.deleteSetMeal(ids);

    }


    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        return setMealService.getById(id);
    }

    /**
     * 修改套餐信息
     * @param dto
     * @return
     */
    @PutMapping
    @CacheEvict(value = "setmealCache" ,key = "#dto.categoryId")
    public Result updateSetMeal(@RequestBody SetmealDTO dto){
        return setMealService.updateSetMeal(dto);

    }


    /**
     * 修改售卖状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @CacheEvict(value = "setmealCache" ,allEntries = true)
    public Result updateStatus(@PathVariable Integer status,Long id){
        return setMealService.updateStatus(status,id);
    }

}
